#include<stdio.h>
#include<string.h>
#define _CRT_SECURE_NO_WARNINGS

struct Stu
{
	char name[20];
	int age;
};
int cmp_name(const void *p1, const void * p2)
{
	return strcmp(((struct Stu*)p1)->name, ((struct Stu*)p2)->name);
}


void swap(char* p1, char* p2,size_t width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = *p1;
		*p1 = *p2;
		*p2 = tmp;
		p1++;
		p2++;
	}
}


void bull_arr(void* arr, size_t sz, size_t width, int(*cmp_name)(const void* p1, const void* p2))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp_name((char*)arr + j * width, (char*)arr + (j + 1) * width) > 0)
				swap((char*)arr + j * width, (char*)arr + (j + 1) * width,width);
		}
	} 
}


void print(struct Stu* p, int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s %d\n", (p+i)->name,(p+i)->age);
	}
}
void test()
{
	struct Stu arr[] = { {"zhangsan",18},{"lisi",35},{"wangwu",15}};
	int sz = sizeof(arr) / sizeof(arr[0]);
	bull_arr(arr, sz, sizeof(arr[0]), cmp_name);
	print(arr, sz);
}


int main()
{
	test();
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	char arr[] = "abcdasdf@121213.lijun#666";
	char* p = arr;
	char* s = NULL;
	char arr1[] = "@.#";
	for (s = strtok(p, arr1); s != NULL; s = strtok(NULL, arr1))
	{
		printf("%s\n", s);
	}
	return 0;
}